<?php
/**
 * Created by PhpStorm.
 * User: zhangligang
 * Date: 17/4/23
 * Time: 下午11:55
 */

namespace App\Http\Repository;


use App\Http\Models\Product;

class ProductRepository implements Repository
{

    private $product;

    /**
     * @param Product $product
     */
    public function __construct(Product $product)
    {
        $this->product = $product;

    }

    /**
     * @param array $where
     * @param int $offset
     * @param int $limit
     * @param array $columns
     * @return mixed
     */
    public function getProductList(array $where, $offset = 0, $limit = 10, array $columns = ['*'])
    {

        $query = $this->product;

        foreach ($where as $item) {

            $query->where($item['key'], $item['operator'], $item['value']);

        }

        return $query->offset($offset)->limit($limit)->get($columns);

    }

    /**
     * @param int $id
     * @param array $columns
     * @return mixed
     */
    public function getProductById($id, array $columns = ['*'])
    {
        return $this->product->find($id, $columns);

    }

}